package cn.iocoder.yudao.module.resource.api.enums;

import cn.iocoder.yudao.framework.common.exception.ServiceException;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 音频关联类型
 *
 * @author 王广帅
 * @version 1.0.0
 * @since 2024/9/4 23:05
 */
public enum EnumAudioRelationType {
    DEFAULT(1),
    QUESTION_ANSWER(2);
    private int type;

    EnumAudioRelationType(int type) {
        this.type = type;
    }

    @JsonValue
    public int getType() {
        return type;
    }

    public static EnumAudioRelationType getEnumType(int type) {
        for (EnumAudioRelationType relationType : EnumAudioRelationType.values()) {
            if (relationType.getType() == type) {
                return relationType;
            }
        }
        return null;
    }

    public static void checkHasType(int type) {
        EnumAudioRelationType relationType = getEnumType(type);
        if (relationType == null) {
            throw new ServiceException(EnumAipError.RELATION_TYPE_ERROR);
        }
    }
}
